<template>
  <div ref="userList" class="user-list">
    <div class="user">
      <div v-if="Ulogin">
          <div class="member">
            <div class="header-con">
              <router-link :to="{name:'login'}" class="mui-navigate-right">
                <div class="user-info">
                  <div class="avatar-con">
                    <div class="avatar">
                      <img src="../assets/images/avatar_default.png" alt="" class="image-info">
                    </div>
                  </div>
                  <div class="person-con">
                    <span>admin</span>
                  </div>
                </div>
              </router-link>
            </div>
          </div>
      </div>
      <div v-else>
        <div class="member">
            <div class="header-con">
              <router-link :to="{name:'login'}" class="mui-navigate-right">
                <div class="user-info">
                  <div class="avatar-con">
                    <div class="avatar">
                      <img src="../assets/images/avatar_default.png" alt="" class="image-info">
                    </div>
                  </div>
                  <div class="person-con">
                    <span>登录 / 注册</span>
                  </div>
                </div>
              </router-link>
            </div>
        </div>
      </div>
      <div class="user-toolbar">
        <ul>
          <li> <span class="iconfont icon">&#xe633;</span> 待付款</li>
          <li> <span class="iconfont icon">&#xe648;</span> 待收货</li>
          <li><span class="iconfont icon">&#xe6d0;</span> 退货</li>
          <li> <span class="iconfont icon">&#xe897;</span> 全部订单</li>
          <li> <span class="iconfont icon">&#xe650;</span> 收藏的店铺</li>
          <li> <span class="iconfont icon">&#xe606;</span> 优惠券</li>
          <li> <span class="iconfont icon">&#xe667;</span> 联系客服</li>
          <li> <span class="iconfont icon">&#xe783;</span> 好友</li>
        </ul>
      </div>
      <div class="user-my">
        <div>个人中心</div>
        <div>收货地址<van-icon name="arrow" class="user-my-icon"/></div>
        <div>联系客服<van-icon name="arrow" class="user-my-icon"/></div>
        <div  @click="showPopup">退出登录<van-icon name="arrow" class="user-my-icon"/></div>
      </div>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name: 'User',
  data () {
    return {
      Ulogin: true,
      isshow: false
    }
  },
  methods: {
    isLogin () {
      return localStorage.getItem('token')
    },
    showPopup () {
      this.$dialog.confirm({
        message: '是否确认要退出登录',
        confirmButtonColor: 'red'
      }).then(() => {
        if (!this.Ulogin) {
          this.$notify({
            message: '当前不是登录状态',
            color: '#ad0000',
            background: '#ffe1e1'
          })
        } else {
          const tk = localStorage.removeItem('token')
          if (tk !== 'Bearer xxxx') {
            this.Ulogin = false
          }
          this.$notify({
            message: '退出登录成功',
            color: '#ad0000',
            background: '#ffe1e1'
          })
        }
      }).catch(() => {
        this.$notify({
          message: '你取消了退出登录',
          color: '#ad0000',
          background: '#ffe1e1'
        })
      })
    },
    getBscoll () {
      this.$nextTick(() => {
        this.scroll = new BScroll(this.$refs.userList, {
          click: {
            type: Boolean,
            default: true
          }
        })
      })
    }
  },
  mounted () {
    if (window.name === '') {
      console.log('首次加载')
      this.Ulogin = false
      window.name = 'isRefresh'
    } else if (window.name === 'isRefresh') {
      if (localStorage.getItem('token') === null) {
        this.Ulogin = false
      }
      console.log(localStorage.getItem('token'))
      console.log('页面被刷新')
    }
    this.getBscoll()
  }
}
</script>

<style lang="scss" scoped>
.user-list{
  background-color: rgb(247, 247, 247);
  overflow: hidden;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 50px;
  right: 0;
  .user{
    .member {
      .header-con {
        width: 100vw;
          height: 220px;
          background-color: #dd524d;
        .user-info {
          height: 100%;
          position: relative;
          // overflow: hidden;
          .avatar-con {
            position: absolute;
            top: 20%;
            left: 50%;
            transform: translateX(-50%);
            .avatar {
              width: 100px;
              height: 100px;
              overflow: hidden;
              box-shadow: 0 3px 4px rgba(0, 0, 0, .15);
              border:1px solid (0, 0%, 100%, 0.4);
              border-radius: 50% 50%;
              .image-info{
                width: 100%;
                height: 100%;
              }
            }
          }
          .person-con{
            line-height: 30px;
            width: 100px;
            position: absolute;
            left: 50%;
            top: 70%;
            transform: translateX(-50%);
            font-size: 16px;
            font-weight: bold;
            text-align: center;
            background-color: #fff;
            color: #dd524d;
            border-radius:20px;
          }
        }
      }
    }
    .user-toolbar{
      margin-bottom: 1rem;
      ul{
        padding: 12px 0;
        display: flex;
        flex-wrap: wrap;
        background-color: #ffffff;
        box-shadow: 0px 3px 2px rgba(0, 0, 0,.1);
        border-radius: 2%;
        margin-top: 1px;
        li{
          width: 25%;
          padding: 10px 6px;
          display: flex;
          flex-direction: column;
          justify-content: center;
          text-align: center;
          color: #dd524d;
          .icon{
            font-size: 25px;
            margin-bottom: 5px;
          }

        }
      }
    }
    .user-my{
      background-color: #fff;
      box-shadow: 0px 3px 2px rgba(0, 0, 0,.1);
      border-radius: 2%;
      text-indent: 8px;
      margin-bottom: 20px;
      &>div{
        padding: 15px 0;
        .user-my-icon{
          position: absolute;
          right: 8px;
        }
      }
    }
  }
}
</style>
